package com.xdw.szpxapp.slice;

import com.xdw.szpxapp.ResourceTable;
import com.xdw.szpxapp.provider.ContactsProvider;
import com.xdw.szpxapp.utils.GenerateStaticData;
import com.yan.zrefreshview.LogUtil;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.BaseItemProvider;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.ListContainer;
import ohos.agp.window.dialog.ToastDialog;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import java.util.List;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private static final HiLogLabel LABEL_LOG = new HiLogLabel(0, 0, "MainAbilitySlice.class");
    private Image ivAdd;
    private Image ivMenu;
    private ListContainer lvContacts;

    private BaseItemProvider provider;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initView();
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    private void initView() {
        ivAdd = (Image) findComponentById(ResourceTable.Id_iv_add);
        ivMenu = (Image) findComponentById(ResourceTable.Id_iv_menu);
        lvContacts = (ListContainer)findComponentById(ResourceTable.Id_lv_contacts);
        ivAdd.setClickedListener(this);
        ivMenu.setClickedListener(this);

        provider = new ContactsProvider(GenerateStaticData.getContactsList(),this);
        lvContacts.setItemProvider(provider);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()){
            case ResourceTable.Id_iv_add:
                HiLog.error(LABEL_LOG, "点击了加号图片");
                new ToastDialog(getContext()).setText("点击了加号图片").setDuration(3000).show();
                break;
            case ResourceTable.Id_iv_menu:
                HiLog.error(LABEL_LOG, "点击菜单图片");
                new ToastDialog(getContext()).setText("点击菜单图片").setDuration(3000).show();
                break;
        }
    }
}
